package thread_01;

public class Demo39 {
    private static int sum = 0;
    public static void main(String[] args) throws InterruptedException {

//        创建一个线程，让线程来实现1+2+3+4+.....+1000
        Thread t1 = new Thread(new Runnable() {
            int result = 0;
            @Override
            public void run() {
                for (int i = 1; i <= 1000; i++) {
                    result += i;
                }
//                此处为了把result告知主线程，需要通过成员变量倒腾一下
                sum = result;
            }
        });

        t1.start();
        t1.join();
//        主线程获取结果
        System.out.println(sum);
    }
}
